﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using LearnThemselvesEffectively.Forms;
using LearnThemselvesEffectively.Classes;

namespace LearnThemselvesEffectively
{
    /// <summary>
    /// Interaction logic for frmRootUI.xaml
    /// </summary>
    public partial class frmRootUI : Window
    {
        Point moDownPoint;
        bool moAllowMoveWindow;
        private string msRootImage;
        public string RootImage { get { return msRootImage; } }

        public frmRootUI()
        {
            InitializeComponent();

            moAllowMoveWindow = false;
            msRootImage = "pack://application:,,,/Resources/learnOwl.gif";
        }        

        private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            moDownPoint = new Point(Mouse.GetPosition(this).X, Mouse.GetPosition(this).Y);
            moAllowMoveWindow = true;
        }

        private void StackPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            moAllowMoveWindow = false;
        }

        private void StackPanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (moAllowMoveWindow == false)
            {
                return;
            }
            Point location = new Point(
                this.Left + e.GetPosition(this).X - moDownPoint.X,
                this.Top + e.GetPosition(this).Y - moDownPoint.Y);
            this.Left = location.X;
            this.Top = location.Y;
        }

        private void btnStartTest_MouseEnter(object sender, MouseEventArgs e)
        {
            msRootImage = "pack://application:,,,/Resources/testOwl.gif";
            this.imgRoot.Dispatcher.Invoke(DispatcherPriority.Render, (Action)delegate { this.imgRoot.Source = new ImageSourceConverter().ConvertFromString(msRootImage) as ImageSource; });
        }

        private void btnOption_MouseEnter(object sender, MouseEventArgs e)
        {
            msRootImage = "pack://application:,,,/Resources/optionOwl.gif";
            this.imgRoot.Dispatcher.Invoke(DispatcherPriority.Render, (Action)delegate { this.imgRoot.Source = new ImageSourceConverter().ConvertFromString(msRootImage) as ImageSource; });
        }

        private void btnExit_MouseEnter(object sender, MouseEventArgs e)
        {
            msRootImage = "pack://application:,,,/Resources/exitOwl.gif";
            this.imgRoot.Dispatcher.Invoke(DispatcherPriority.Render, (Action)delegate { this.imgRoot.Source = new ImageSourceConverter().ConvertFromString(msRootImage) as ImageSource; });
        }

        private void btnLearn_MouseEnter(object sender, MouseEventArgs e)
        {
            msRootImage = "pack://application:,,,/Resources/learnOwl.gif";
            this.imgRoot.Dispatcher.Invoke(DispatcherPriority.Render, (Action)delegate { this.imgRoot.Source = new ImageSourceConverter().ConvertFromString(msRootImage) as ImageSource; });
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnLearn_Click(object sender, RoutedEventArgs e)
        {
            GlobalSupportModele.TranslationWindowModule = GlobalSupportModele.eTranslationWindowModule.Learn; 
            GlobalSupportModele.OpenNewFrameCloseOwner(new frmProxyOptions(), this);
        }

        private void btnStartExam_Click(object sender, RoutedEventArgs e)
        {
            GlobalSupportModele.TranslationWindowModule = GlobalSupportModele.eTranslationWindowModule.Exam;
            GlobalSupportModele.OpenNewFrameCloseOwner(new frmProxyOptions(), this);
        }
    }
}
